// pages/BankCard/BankCard.js
const app = getApp();
const util = require('../../../utils/util.js')
const http = require('../../../utils/http.js');
Page({

  /**
   * 
   * 页面的初始数据
   */
  data: {
    load: false,
    isShow: false,
    tops: Number(getApp().globalData.statusBarHeight + 48)
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let content = wx.getStorageSync('content');
    if (options.agent) {
      let agent = options.agent;
      this.setData({
        agent: agent
      })
      if (content) {

      } else {
        this.setData({
          load: true,
          isShow: true
        })
        wx.redirectTo({
          url: '/pages/onNewPages/Accredit/Accredit?agent=' + agent,
        })
      }
    }

    // this.getBankOwner();
    // this.bankList();
    let type = options.type;
    this.setData({
      type: type
    })
  },
  back() {

    let type = this.data.type;
    let agent = this.data.agent;

    if (type == 1) {
      wx.switchTab({
        url: '../UserCenter/userCenter',
      })
    } else if (agent == 3) {
      wx.navigateBackMiniProgram({
        success: res => {
          wx.switchTab({
            url: '../UserCenter/userCenter',
          })
        }
      })
    } else {
      wx.navigateBack({
        delta: 1
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.Modal = this.selectComponent("#modal");
    this.toastDialog = this.selectComponent("#toastDialog"); //此处id和页面的 wxml中的id一致
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.toasts = this.selectComponent('#toasts')

    this.getBankOwner('');
    this.getRealnameInfo('')

  },
  //判断实名
  getRealnameInfo(data) {

    let _this = this
    _this.toasts.showToast({
      type: 'fail',
      title: '加载中',
      duration: 7000,
    })
    http.getRequest('v1/getRealnameInfo', data,
      function (res) {
        _this.toasts.hideToast({})
        _this.setData({
          realname: res.data.realname,
          id_card: res.data.id_card
        })
      },
      function (err) {

      })

  },

  //跳转添加银行卡
  bind() {
    let member = wx.getStorageSync('member')
    if (wx.getStorageSync('renzheng') != '1') {
      this.Modal.showModal();
    } else {
      let realname = this.data.realname
      let id_card = this.data.id_card
      wx.navigateTo({
        url: '/pages/onNewPages/CardInfo/CardInfo?realname=' + realname + '&id_card=' + id_card + '&&agent=0',
      })

    }
    // let is_card = member.member_info.member_info.id_card
    // let bank = this.data.bank;
    // let is_card = this.data.is_card;
    // if (is_card == 0) {
    //   this.Modal.showModal();
    // } else {
    // let realname = this.data.realname;
    // let agent = this.data.agent;

    // }

  },
  _confirmEventFirst: function () {
    this.Modal.hideModal();
    //代理小程序跳转
    wx.navigateTo({
      url: '/pages/onNewPages/Certification/Certification',
    })

  },
  _cancelEvent: function () {
    this.Modal.hideModal();

  },
  //银行卡列表
  getBankOwner(data) {

    let _this = this
    http.getRequest('v1/bank', data,
      function (res) {
        for (let i in res.data.list) {
          res.data.list[i].bank_card = res.data.list[i].bank_card.substring( res.data.list[i].bank_card.length - 4)
        }
        _this.setData({
          bankList: res.data.list,
        })
      },
      function (err) {})

  },
})